import pymongo


def getClient():
    myClient = pymongo.MongoClient("mongodb://localhost:27017/")
    return myClient


def save(client):
    myDb = client["w3cschooldb"]
    myCol = myDb["sites"]
    myquery = {"alexa": "10000"}
    newValues = {"$set": {"alexa": "123456"}}
    myCol.update_one(myquery, newValues)
    for x in myCol.find():
        print(x)

    myquery = {"name": {"$regex": "^F"}}
    newValues = {"$set": {"alexa": "123"}}
    x = myCol.update_many(myquery, newValues)
    print(x.modified_count, "个文档已更新")


if __name__ == "__main__":
    client = getClient()
    save(client)
